package com.deer.wms.inventory.web;

import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.inventory.model.stockTake.StockProfitLoss;
import com.deer.wms.inventory.model.stockTake.StockProfitLossDto;
import com.deer.wms.inventory.service.StockProfitLossService;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

//import com.deer.wms.inventory.service.StockTakeLogService;


/**
* Created by csl on 2021/04/13.
*/
@Api(description = "盈亏单api接口")
@RestController
@RequestMapping("/stock/profit/loss")
public class StockProfitLossController {

    @Autowired
    private StockProfitLossService stockProfitLossService;

    /**
     * //点击生成盈亏单自动生成盘盈入库单，盘亏出库单，并调整库存
     * @param stockProfitLossDto
     * @param currentUser
     * @return
     */
    @PostMapping("/insert")
    public Result add(@RequestBody StockProfitLossDto stockProfitLossDto, @ApiIgnore @User CurrentUser currentUser) {
        stockProfitLossService.createProfitOrLoss(stockProfitLossDto,currentUser);
        return ResultGenerator.genSuccessResult();
    }

    /**
     * 查询盘盈和盘亏单
     * @param wareId
     * @param profitOrLoss
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/findByProfitLoss")
    public Result findByProfitLoss(Integer wareId, Integer profitOrLoss, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<StockProfitLoss>  list = stockProfitLossService.findByProfitLoss(wareId,profitOrLoss);
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.genSuccessResult(pageInfo);
    }
}

